package cn.miju.admin.system.controller;

import cn.miju.admin.system.service.MenuService;
import cn.miju.admin.system.vo.*;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.github.xiaoymin.knife4j.annotations.ApiSort;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <pre>
 * 系统菜单
 * </pre>
 *
 * @author zhuming
 * @version 1.0.0
 * @since 2023-03-29 11:46
 */
@RestController
@Api(tags = "系统-菜单管理")
@ApiSort(2)
@RequestMapping("/system/menu")
public class MenuController {
    private final MenuService service;

    public MenuController(MenuService service) {
        this.service = service;
    }
    /**
     * 获取系统菜单
     * @param inVO {@link MenuListInVO}
     * @return {@link MenuListOutVO}
     */
    @ApiOperation("获取系统菜单")
    @ApiOperationSupport(order = 1, author = "zhuming")
    @PostMapping("/list")
    public MenuListOutVO getMenuList(@RequestBody @Validated MenuListInVO inVO) {
        return service.getMenuList(inVO.getRoleId());
    }
    /**
     * 获取用户菜单
     * @param inVO {@link UserMenuListInVO}
     * @return {@link UserMenuListOutVO}
     */
    @ApiOperation("获取用户菜单")
    @ApiOperationSupport(order = 2, author = "zhuming")
    @PostMapping("/userList")
    public UserMenuListOutVO getUserMenuList(@RequestBody @Validated UserMenuListInVO inVO) {
        return service.getUserMenuList(inVO.getRoleIds());
    }

    /**
     * 获取菜单树
     * @return {@link List<MenuTreeOutVO>}
     */
    @ApiOperation("获取菜单树")
    @ApiOperationSupport(order = 3, author = "zhuming")
    @GetMapping("/tree")
    public List<MenuTreeOutVO> getMenuTree() {
        return service.getMenuTree();
    }

    /**
     * 保存菜单
     * @param inVO {@link MenuSaveInVO}
     * @return 菜单ID
     */
    @ApiOperation("保存菜单")
    @ApiOperationSupport(order = 4, author = "zhuming")
    @PostMapping("/save")
    public Long save(@RequestBody @Validated MenuSaveInVO inVO) {
        return service.saveMenu(inVO);
    }

    /**
     * 授权菜单
     * @param inVO {@link AuthMenuInVO}
     */
    @ApiOperation("授权菜单")
    @ApiOperationSupport(order = 5, author = "zhuming")
    @PostMapping("/auth")
    public void auth(@RequestBody @Validated AuthMenuInVO inVO) {
        service.authMenu(inVO);
    }

    /**
     * 批量删除菜单
     * @param inVO {@link MenuDeleteInVO}
     */
    @ApiOperation("批量删除菜单")
    @ApiOperationSupport(order = 6, author = "zhuming")
    @PostMapping("/deletes")
    public void deletes(@RequestBody @Validated MenuDeleteInVO inVO) {
        service.deletes(inVO);
    }
}

